﻿<?php
defined("_VALID_ACCESS") || die('Direct access forbidden');
class SCTV_MaintenanceInstall extends ModuleInstall {
    public function install() { // Here you can place the installation process for the module
    	Utils_CommonDataCommon::new_array('SCTV/Maintenance/Status',array(_M('In Progress'),_M('Completed'),_M('Canceled')), true,true);
		Utils_CommonDataCommon::new_array('SCTV/Maintenance/Todo',array(_M('Task of business'),_M('Task of technical'),_M('Task of accountant')), true,true);
	
		Base_ThemeCommon::install_default_theme($this->get_type());
				
		$fields = array(			
			array('name'=>_M('Maintenance Group'), 'type'=>'select', 'param'=>array('SCTV_MaintenanceGroup'=>'Name'), 'required'=>true, 'visible'=>false),
			array('name'=>_M('Customer Name'), 'type'=>'text', 'param'=>128, 'required'=>false, 'visible'=>true, 'display_callback'=>array('SCTV_MaintenanceCommon', 'display_customer_name')),											
			array('name'=>_M('Address'), 'type'=>'text', 'param'=>128, 'required'=>true, 'visible'=>true),
			array('name'=>_M('Street'), 'type'=>'select', 'param'=>array('SCTV_Street'=>'Name'), 'required'=>false, 'visible'=>true, 'display_callback'=>array('SCTV_MaintenanceCommon', 'display_street')),
			array('name'=>_M('District'), 'type'=>'commondata', 'param'=>array('Countries/VN/QN'), 'extra'=>true, 'required'=>false, 'visible'=>false),
			array('name'=>_M('Ward'), 'type'=>'commondata', 'param'=>array('Countries/VN/QN', 'District'), 'extra'=>true, 'required'=>false, 'visible'=>false),
			array('name'=>_M('Phone'), 'type'=>'text', 'param'=>64, 'required'=>true, 'visible'=>true),			
			array('name'=>_M('Status'), 'type'=>'commondata', 'param'=>array('order_by_key'=>true,'SCTV/Maintenance/Status'), 'required'=>true, 'visible'=>true, 'display_callback'=>array('SCTV_MaintenanceCommon', 'display_status'), 'QFfield_callback'=>array('SCTV_MaintenanceCommon', 'QFfield_status')),			
			array('name'=>_M('Counselor'), 'type'=>'crm_contact', 'param'=>array('field_type'=>'select', 'crits'=>array(), 'format'=>array('CRM_ContactsCommon','contact_format_default')), 'required'=>true, 'visible'=>true),
			array('name'=>_M('Requirement Date'), 'type'=>'date', 'required'=>false, 'visible'=>true),
			array('name'=>_M('Requirement Time'), 'type'=>'time', 'required'=>false, 'visible'=>true),
			array('name'=>_M('Delivery Date'), 'type'=>'date', 'required'=>true, 'visible'=>true),
			array('name'=>_M('Maintenance Code'), 'type'=>'calculated', 'param'=>Utils_RecordBrowserCommon::actual_db_type('text', 16), 'required'=>false, 'visible'=>true, 'extra'=>false, 'display_callback'=>array('SCTV_MaintenanceCommon', 'display_maintenance_code')),						
			array('name'=>_M('Note'), 'type'=>'text', 'param'=>300, 'required'=>false, 'visible'=>true),
			array('name'=>_M('Acceptance Report'), 'type'=>'page_split', 'param'=>3),
			array('name'=>_M('Maintenance Date'), 'type'=>'date', 'required'=>false, 'visible'=>false),	
			array('name'=>_M('Maintenance Time'), 'type'=>'time', 'required'=>false, 'visible'=>false),
			array('name'=>_M('Acceptance Date'), 'type'=>'date', 'required'=>false, 'visible'=>false),
			array('name'=>_M('Deployment Employee'), 'type'=>'crm_contact', 'param'=>array('field_type'=>'select', 'crits'=>array(), 'format'=>array('CRM_ContactsCommon','contact_format_default')), 'required'=>false, 'visible'=>false),
			array('name'=>_M('Customer Code'), 'type'=>'text', 'param'=>64, 'required'=>false, 'visible'=>true, 'display_callback'=>array('SCTV_MaintenanceCommon', 'display_customer_code')),						
			array('name'=>_M('Charge'), 'type'=>'integer', 'required'=>true, 'visible'=>true, 'display_callback'=>array('SCTV_MaintenanceCommon', 'display_charge')),
			array('name'=>_M('Other Information'), 'type'=>'page_split', 'param'=>3),
			array('name'=>_M('Manager Area'), 'type'=>'select', 'param'=>array('SCTV_Area'=>'Name'), 'extra'=>false, 'visible'=>false, 'required'=>false),
			array('name'=>_M('Lastest Update Day'), 'type'=>'timestamp', 'extra'=>0, 'visible'=>false, 'required'=>false),
			array('name'=>_M('Review'), 'type'=>'checkbox', 'extra'=>0, 'visible'=>false, 'required'=>false, 'display_callback'=>array('SCTV_MaintenanceCommon', 'display_review'), 'QFfield_callback'=>array('SCTV_MaintenanceCommon', 'QFfield_review')),
			array('name'=>_M('Review Note'),'type'=>'text', 'param'=>256, 'extra'=>0, 'visible'=>false, 'required'=>false)
		);
		
		Utils_RecordBrowserCommon::install_new_recordset('SCTV_Maintenance', $fields);
		Utils_RecordBrowserCommon::register_processing_callback('SCTV_Maintenance', array('SCTV_MaintenanceCommon', 'process_request'));
		Utils_RecordBrowserCommon::set_caption('SCTV_Maintenance', _M('Maintenance'));
		Utils_RecordBrowserCommon::add_default_access('SCTV_Maintenance');		
		Utils_AttachmentCommon::new_addon('SCTV_Maintenance');
		
		$StatusHistoryFields = array(
			array('name'=>_M('Maintenance'), 'type'=>'select', 'param'=>array('SCTV_Maintenance'=>'Customer Name'), 'required'=>true, 'visible'=>false),
			array('name'=>_M('Date Time'), 'type'=>'timestamp', 'required'=>true, 'visible'=>true),						
			array('name'=>_M('Employee'), 'type'=>'crm_contact', 'param'=>array('field_type'=>'select', 'crits'=>array(), 'format'=>array('CRM_ContactsCommon','contact_format_default')), 'required'=>true, 'visible'=>true),
			array('name'=>_M('Status'), 'type'=>'commondata', 'param'=>array('order_by_key'=>true,'SCTV/Maintenance/Status'), 'required'=>true, 'visible'=>true),											
			array('name'=>_M('Note'), 'type'=>'text', 'param'=>128, 'required'=>false, 'visible'=>true)
		);
		
		Utils_RecordBrowserCommon::install_new_recordset('SCTV_MaintenanceStatusHistory', $StatusHistoryFields);
		Utils_RecordBrowserCommon::set_caption('SCTV_MaintenanceStatusHistory', _M('Maintenance Status History'));
		Utils_RecordBrowserCommon::add_default_access('SCTV_MaintenanceStatusHistory');
		
		Utils_RecordBrowserCommon::new_addon('SCTV_Maintenance', 'SCTV/Maintenance', 'maintenance_status_history_addon', _M('Maintenance Status History'));
		
		$DeliveryDateHistoryFields = array(
			array('name'=>_M('Maintenance'), 'type'=>'select', 'param'=>array('SCTV_Maintenance'=>'Customer Name'), 'required'=>true, 'visible'=>false),
			array('name'=>_M('Date Time'), 'type'=>'timestamp', 'required'=>true, 'visible'=>true),						
			array('name'=>_M('Employee'), 'type'=>'crm_contact', 'param'=>array('field_type'=>'select', 'crits'=>array(), 'format'=>array('CRM_ContactsCommon','contact_format_default')), 'required'=>true, 'visible'=>true),
			array('name'=>_M('Delivery Date'), 'type'=>'date', 'required'=>true, 'visible'=>true),											
			array('name'=>_M('Note'), 'type'=>'text', 'param'=>128, 'required'=>false, 'visible'=>true)
		);
		
		Utils_RecordBrowserCommon::install_new_recordset('SCTV_MaintenanceDeliveryDateHistory', $DeliveryDateHistoryFields);
		Utils_RecordBrowserCommon::set_caption('SCTV_MaintenanceDeliveryDateHistory', _M('Maintenance Delivery DateHistory'));
		Utils_RecordBrowserCommon::add_default_access('SCTV_MaintenanceDeliveryDateHistory');
		
		Utils_RecordBrowserCommon::new_addon('SCTV_Maintenance', 'SCTV/Maintenance', 'maintenance_delivery_date_history_addon', _M('Maintenance Delivery Date History'));
		
		return true; // Return true on success and false on failure
	}
 
    public function uninstall() { // Here you can place uninstallation process for the module
    	Utils_RecordBrowserCommon::unregister_processing_callback('SCTV_Maintenance', array('SCTV_MaintenanceCommon', 'process_request'));
		Base_ThemeCommon::uninstall_default_theme($this->get_type());
		Utils_RecordBrowserCommon::uninstall_recordset('SCTV_Maintenance');
	
		Utils_CommonDataCommon::remove('SCTV/Maintenance/Status');
		Utils_CommonDataCommon::remove('SCTV/Maintenance/Todo');
		
		Utils_RecordBrowserCommon::uninstall_recordset('SCTV_MaintenanceStatusHistory');
		Utils_RecordBrowserCommon::uninstall_recordset('SCTV_MaintenanceDeliveryDateHistory');
		return true;
    }
 
 	public function requires($v) {
		return array(
			array('name'=>'Utils/RecordBrowser', 'version'=>0),
			array('name'=>'Utils/Attachment', 'version'=>0),
			array('name'=>'CRM/Common', 'version'=>0),
			array('name'=>'Base/Lang', 'version'=>0),
			array('name'=>'Base/Acl', 'version'=>0),
			array('name'=>'Data/Countries', 'version'=>0)
		);
	}
	
    public function info() { // Returns basic information about the module which will be available in the epesi Main Setup
 
        return array( 'Author'=>'Tran Trong Hieu',
            'License'=>'SCTV',
                     'Description'=>'Maintenance');
 
    }
 
    public function simple_setup() { // Indicates if this module should be visible on the module list in Main Setup's simple view
 
        return array('package' => __('Maintenance'), 'version'=>'1.0'); // - now the module will be visible as "HelloWorld" in simple_view
 
    }

 
    public function version() { // Return version name of the module
 
        return array('1.1');
 
    }
}
 
?>